package com.groupsix.controller;

import com.groupsix.entity.Stgrade;
import com.groupsix.service.StgradeService;
import com.groupsix.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 学生卫生控制器
 * @date 2021/10/17 23:02
 */
@Controller
public class StgradeController {
    //依赖注入
    @Autowired
    private StgradeService stgradeService;

    /**
     * 分页查询
     * pageIndex 当前页码
     * pageSize  显示条数
     */
    @RequestMapping("/findStgrade.action")
    public String findStgrade(Integer sStudentid, String sName, Integer sDormitoryid, Integer pageIndex, Integer pageSize, Model model) {

        PageInfo pi = stgradeService.findPageInfo(sStudentid,sName,sDormitoryid,pageIndex,pageSize);
        model.addAttribute("di",pi);
        return "studentclean_list";
    }


    /**
     * 添加宿舍卫生信息
     */
    @RequestMapping("/addStgrade.action")
    @ResponseBody
    public String addStgrade( @RequestBody Stgrade stgrade) {
        int d = stgradeService.addStgrade(stgrade);
        return "stgrade_list";
    }

    /**
     * 删除宿舍卫生信息
     */
    @RequestMapping( "/deleteStgrade.action")
    @ResponseBody
    public String deleteStgrade(Integer gId) {
        int d = stgradeService.deleteStgrade(gId);
        return "stgrade_list";
    }

    /**
     * 修改宿舍卫生信息
     */
    @RequestMapping( "/updateStgrade.action")
    public String updateStgrade( Stgrade stgrade) {
        int d = stgradeService.updateStgrade(stgrade);
        return "redirect:/findStgrade.action";
    }


    @RequestMapping( "/findStgradeById.action")
    public String findStgradeById(Integer gId, HttpSession session) {

        Stgrade d= stgradeService.findStgradeById(gId);
        session.setAttribute("d",d);
        return "studentclean_edit";
    }

}
